package org.gwtEss.table;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.google.gwt.user.client.ui.Widget;

//public class UserManagedWidgetInstanceCache extends HashMap<UserManagedColWidgetMapObject, Widget>{
public class UserManagedWidgetInstanceCache<VO> extends HashMap<UserManagedColWidget<VO, ?>, Map<Object, Widget>>{
	public void put(Object data, UserManagedColWidget<VO, ?> colWidget, Widget w){
		Map<Object, Widget> objWMap; 
		if((objWMap = get(colWidget)) == null)
			objWMap = new HashMap<Object, Widget>();
		objWMap.put(data, w);
		put(colWidget, objWMap);
	}
	public void setWidth(int width, UserManagedColWidget<VO, ?> colWidget){
		Map<Object, Widget> map = get(colWidget);
		if (map == null) return; 
		Collection<Widget> vals = map.values();
		if (vals == null) return;
		for (Iterator iterator = vals.iterator(); iterator.hasNext();) {
			Widget widget = (Widget) iterator.next();
			widget.setWidth(width+"px");
		}
	}
	public Widget get(Object data, UserManagedColWidget<VO, ?> colWidget){
		Map<Object, Widget> objWMap;
		if ((objWMap = get(colWidget)) == null) return null;
		return objWMap.get(data);
//		return get(new UserManagedColWidgetMapObject(data, col));//TODO: Bad performance? 
	}
}
